<?php

/**
 * Botenmarkt_front 
 *
 * @category    botenmarkt_front
 * @package     library
 * @subpackage  domainObjects
 * 
 * @author      valerii lazarevych <valeriy.fremar@gmail.com>
 * @copyright   Copyright(c) Fremar ltd.
 * 
 * @license     default
 * @version     4:32:56 PM | Feb 8, 2012
 */

/**
 * Web Link Class
 * 
 * Represent html link with available checking
 */
class   Link_domainObject     extends     domainObject
{
    /**
     * Web Link name
     * 
     * @var string
     */
    public  $name           =       null;
    
    /**
     * Link url
     * 
     * @var string
     */
    public  $url            =       null;    
    
    /**
     * Link availble status
     * 
     * @var bool
     */
    public  $broken         =       null;
    
    /**
     * Empty link pattern
     * 
     * Use when link has broken url
     * 
     * @var string
     */
    private static $emptyLink   =   'Link has broken';

        /**
     * Get link name
     * 
     * @return string
     */
    public function linkName()
    {
        if ( !$this->name )
              $this->name   =  $this->linkUrl(); 
        
        return $this->name;
    }
    
    /**
     * Get link url
     * 
     * @return string
     */
    public function linkUrl()
    {
        if ( $this->linkBroken() )
             $this->url  =   self::$emptyLink;
        
        return  $this->url;
    }
    
    /**
     * Looking has link broken?
     * 
     * And save found link broken status to database
     * 
     * @todo    rebuild boroken look mechanism
     * 
     * @return bool
     */
    public function linkBroken()
    {
//        if ( !$this->broken ){
//              $this->broken   =   (bool)file_get_contents($this->url);
//              $this->save();
//        }        
        return $this->broken;
    }
}

